//
//  HJCMainTabBar.swift
//  新浪微博Swift
//
//  Created by 郝俊聪 on 15/5/10.
//  Copyright (c) 2015年 heima. All rights reserved.
//

import UIKit

class HJCMainTabBar: UITabBar {

 
    
    
    
    //布局控件
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        let viewCount = 5
 
        let h = frame.size.height - 1.0
        let w = (UIScreen.mainScreen().bounds.size.width - 4)/CGFloat(viewCount)
      
        
       var firstFrame = CGRectMake(0, 0, w, h)
        
        //遍历子控件
        var index = 0
        for v in subviews as! [UIView]
        {
//            println("\(v)")
            if v is UIControl && !(v is UIButton)
            {
                v.frame = CGRectOffset(firstFrame, CGFloat(index)*w,CGFloat(0))
                
                index += (index == 1) ? 2 : 1
            }
            
            addBtn.frame = firstFrame
            
            addBtn.center = CGPointMake(center.x, frame.size.height/2)
            
        }
        
    }
    
    

    
    //懒加载按钮
    lazy var addBtn : UIButton = {
        
        let addBtn = UIButton()
        //设置背景图片
        addBtn.setBackgroundImage(UIImage(named:"tabbar_compose_button"), forState: UIControlState.Normal)
        addBtn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Selected)
        
        //设置图片
        addBtn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        addBtn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Selected)
        
        
        //添加
        self.addSubview(addBtn)
        
        return addBtn
        
    }()
    

}
